﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using MySQLStudio.ComponentModel;
using System.Drawing.Design;
using MySQLStudio.BusinessLogic;

namespace MySQLStudio.BusinessLogic.ComponentModel
{
    public class ColumnTypeDescriptor : CustomTypeDescriptor
    {
        private Column column;

        public ColumnTypeDescriptor(Column column, ICustomTypeDescriptor parent)
            : base(parent)
        {
            this.column = column;
        }

        public override PropertyDescriptorCollection GetProperties()
        {
            return this.GetProperties(null);
        }

        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            List<PropertyDescriptor> list = new List<PropertyDescriptor>();

            ColumnPropertyDescriptor pName = new ColumnPropertyDescriptor("Name", column,
                new CategoryAttribute("(General)"));
            ColumnPropertyDescriptor pInPrimaryKey = new ColumnPropertyDescriptor("InPrimaryKey", column,
                new CategoryAttribute("Table Designer"));
            ColumnPropertyDescriptor pIsIdentity = new ColumnPropertyDescriptor("IsIdentity", column,
                new CategoryAttribute("Table Designer"));
            ColumnPropertyDescriptor pDataType = new ColumnPropertyDescriptor("DataType", column,
                new CategoryAttribute("(General)"), new EditorAttribute(typeof(ListGridComboBox), typeof(UITypeEditor)),
                new DataListAttribute("MySQLStudio.Common", "MySQLStudio.Common.DataUtils", "DataTypes.DataTypes", false));
            ColumnPropertyDescriptor pUnsigned = new ColumnPropertyDescriptor("Unsigned", column,
                new CategoryAttribute("Table Designer"));
            ColumnPropertyDescriptor pZerofill = new ColumnPropertyDescriptor("Zerofill", column,
                new CategoryAttribute("Table Designer"));
            ColumnPropertyDescriptor pDefault = new ColumnPropertyDescriptor("Default", column,
                new CategoryAttribute("(General)"), new DisplayNameAttribute("Default Value"));
            ColumnPropertyDescriptor pCollation = new ColumnPropertyDescriptor("Collation", column,
                new CategoryAttribute("Table Designer"), new EditorAttribute(typeof(ListGridComboBox), typeof(UITypeEditor)),
                new DataListAttribute("MySQLStudio.Common", "MySQLStudio.Common.Data.Collations", "ServerCollations", false));
            ColumnPropertyDescriptor pIsNullable = new ColumnPropertyDescriptor("IsNullable", column,
                new CategoryAttribute("(General)"), new DisplayNameAttribute("Allow Nulls"));
            ColumnPropertyDescriptor pLength = new ColumnPropertyDescriptor("Length", column,
                new CategoryAttribute("Table Designer"));
            ColumnPropertyDescriptor pPrecision = new ColumnPropertyDescriptor("Precision", column,
                new CategoryAttribute("Table Designer"));
            ColumnPropertyDescriptor pScale = new ColumnPropertyDescriptor("Scale", column,
                new CategoryAttribute("Table Designer"));
            ColumnPropertyDescriptor pComment = new ColumnPropertyDescriptor("Comment", column,
                new CategoryAttribute("Table Designer"));

            list.Add(pName);
            list.Add(pInPrimaryKey);
            list.Add(pIsIdentity);
            list.Add(pDataType);
            list.Add(pUnsigned);
            list.Add(pZerofill);
            list.Add(pDefault);
            list.Add(pCollation);
            list.Add(pIsNullable);
            list.Add(pLength);
            list.Add(pPrecision);
            list.Add(pScale);
            list.Add(pComment);

            return new PropertyDescriptorCollection(list.ToArray());
        }
    }
}
